#coding:utf8
'''
12453687  42516837
245  425    -->   2   4  5
3687 6837   -->   3   68  7

        1
    2        3
   4 5     6   7
            8
先中序重建
'''

class Solution(object):
    def buildTree(self, preorder, inorder):

        if inorder:
            ind = inorder.index(preorder.pop(0))
            root = TreeNode(inorder[ind])
            root.left = self.buildTree(preorder, inorder[0:ind])
            root.right = self.buildTree(preorder, inorder[ind+1:])
            return root

'''
中后序重建
'''
